package nc.ui.hljt.h00004;

import java.awt.Container;

import nc.ui.ic.pub.LongTimeTask;
import nc.ui.pub.ClientEnvironment;
import nc.ui.pub.pf.PfUtilClient;
import nc.ui.trade.base.AbstractBillUI;
import nc.ui.trade.businessaction.BusinessAction;
import nc.ui.trade.businessaction.IPFACTION;
import nc.vo.hljt.h00004.Ret55VO;
import nc.vo.pub.AggregatedValueObject;

public class ClientBusinessAction extends BusinessAction {
	private boolean isshowdig = false;

	public ClientBusinessAction() {
		super();
	}

	public ClientBusinessAction(AbstractBillUI ui) {
		super(ui);
	}

	public nc.vo.pub.AggregatedValueObject[] save(
			nc.vo.pub.AggregatedValueObject[] billVO, String billType,
			String billDate, Object[] userObj, AggregatedValueObject[] checkVo)
			throws Exception {

		if (billVO == null || billVO.length <= 0) {
			return null;
		}

		for (int i = 0, loop = billVO.length; i < loop; i++) {
			setBillStatus(billVO[i]);
		}
		Object[] retAry = (Object[]) processActionBatch(IPFACTION.SAVE, billVO,
				billType, billDate, userObj);
		if (retAry == null || retAry.length <= 0) {
			return null;
		}
		Ret55VO[] retvos = new Ret55VO[retAry.length];
		System.arraycopy(retAry, 0, retvos, 0, retvos.length);

		return retvos;
	}

	public nc.vo.pub.AggregatedValueObject[] delete(
			nc.vo.pub.AggregatedValueObject[] billVO, String billType,
			String billDate, Object[] userObj) throws Exception {

		processActionBatch(IPFACTION.DELETE, billVO, billType, billDate,
				userObj);

		return billVO;
	}

	public AggregatedValueObject[] commit(AggregatedValueObject billVO[],
			String billType, String billDate, Object[] userObj)
			throws Exception {

		Object[] retAry = (Object[]) processActionBatch(IPFACTION.COMMIT,
				billVO, billType, billDate, userObj);
		if (retAry == null || retAry.length <= 0) {
			return null;
		}
		Ret55VO[] retvos = new Ret55VO[retAry.length];
		System.arraycopy(retAry, 0, retvos, 0, retvos.length);

		return retvos;
	}

	public nc.vo.pub.AggregatedValueObject[] approve(
			AggregatedValueObject[] billVO, String billType, String billDate,
			Object[] userObj) throws Exception {

		Object[] retAry = (Object[]) approveBatch(billVO, billType, billDate,
				userObj);
		if (retAry == null || retAry.length <= 0) {
			return null;
		}
		Ret55VO[] retvos = new Ret55VO[retAry.length];
		System.arraycopy(retAry, 0, retvos, 0, retvos.length);

		return retvos;
	}

	public nc.vo.pub.AggregatedValueObject edit(
			nc.vo.pub.AggregatedValueObject billVO, java.lang.String billType,
			java.lang.String billDate, java.lang.Object userObj)
			throws java.lang.Exception {

		return null;
	}

	public nc.vo.pub.AggregatedValueObject[] unapprove(
			nc.vo.pub.AggregatedValueObject[] billVO, String billType,
			String billDate, Object[] userObj) throws Exception {

		Object[] retAry = null;

		retAry = PfUtilClient.processBatchFlow(getUI(), IPFACTION.UNAPPROVE
				+ ClientEnvironment.getInstance().getUser().getPrimaryKey(),
				billType, billDate, billVO, userObj);

		if (retAry == null || retAry.length <= 0) {
			return null;
		}

		Ret55VO[] retvos = new Ret55VO[retAry.length];
		System.arraycopy(retAry, 0, retvos, 0, retvos.length);

		return retvos;
	}

	public Object processActionBatch(String actionname,
			nc.vo.pub.AggregatedValueObject[] billVO, String billType,
			String billDate, Object[] userObj) throws Exception {

		if (isshowdig) {

			return LongTimeTask.callAction(getUI(), null, "processBatch",
					new Class[] { Container.class, String.class, String.class,
							String.class, AggregatedValueObject[].class,
							Object[].class }, new Object[] { getUI(),
							actionname, billType, billDate, billVO, userObj });

		} else {

			return PfUtilClient.processBatch(getUI(), actionname, billType,
					billDate, billVO, userObj);

		}
	}

	public Object approveBatch(AggregatedValueObject[] billVO, String billType,
			String billDate, Object[] userObj) throws Exception {

		return PfUtilClient.processBatchFlow(getUI(), IPFACTION.APPROVE,
				billType, billDate, billVO, userObj);
	}
}
